package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.entity.SysAdminT;
import com.panshi.service.impl.SysAdminTServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 后台管理员表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-13
 */
@RestController
@Api("后台管理员表 前端控制器")
public class SysAdminTController {

    @Autowired
    private SysAdminTServiceImpl sysAdminTService;

    //按邮箱搜索管理员
    @ApiOperation("按邮箱搜索管理员")
    @GetMapping("/sys-admin-t/getAdminEmail/{email}")
    public SysAdminT getAdminEmail(@PathVariable String email){
        SysAdminT admin_email = sysAdminTService.getOne(new QueryWrapper<SysAdminT>().eq("admin_email", email));
        return admin_email;
    }

    //按手机号搜索管理员
    @ApiOperation("按手机号搜索管理员")
    @GetMapping("/sys-admin-t/getAdminPhone/{phone}")
    public SysAdminT getAdminPhone(@PathVariable String phone){
        SysAdminT admin_telephone = sysAdminTService.getOne(new QueryWrapper<SysAdminT>().eq("admin_telephone", phone));
        return admin_telephone;
    }

    //查询全部管理员
    @ApiOperation("查询全部管理员")
    @GetMapping("/sys-admin-t/getAdminAll")
    public List<SysAdminT> getAdminAll(){
        return sysAdminTService.list(null);
    }

    @ApiOperation("按ID查询管理员")
    @GetMapping("/sys-admin-t/getAdminById/{id}")
    public SysAdminT getAdminById(@PathVariable int id){
        return sysAdminTService.getById(id);
    }


    @ApiOperation("按用户名查询  加分页")
    @GetMapping("/user/getUserByName/{adminname}/{status}/{page}/{limit}")
    public List<SysAdminT> getAdminLikeName(@PathVariable String adminname,@PathVariable String status,@PathVariable int page,@PathVariable int limit){
        System.out.println(adminname+" "+status);
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<SysAdminT> pageParam = new Page<>(page, limit);
        QueryWrapper<SysAdminT> wrapper = new QueryWrapper<>();

        if(!status.equals("-1")){//是否被冻结
            wrapper.eq("admin_status",status);
        }
        if(adminname!=null&& !adminname.equals("-1")){//昵称查询
            wrapper.like("admin_name",adminname);
        }
        sysAdminTService.page(pageParam,wrapper);

        List<SysAdminT> userPageAll = pageParam.getRecords();
        return userPageAll;
    }



}

